#include<bits/stdc++.h>
using namespace std;
#define int long long

int n, m;
char ch[105][105];
bool vis[105][105];

void dfs(int x, int y) {
	if (x < 1 || x > n || y < 1 || y > m)
		return ;
	if (vis[x][y])
		return ;
	if (ch[x][y] != 'L')
		return ;
	vis[x][y] = 1;
	dfs(x - 1, y - 1);
	dfs(x - 1, y);
	dfs(x - 1, y + 1);
	dfs(x + 1, y);
	dfs(x + 1, y - 1);
	dfs(x + 1, y + 1);
	dfs(x, y - 1);
	dfs(x, y + 1);
}

signed main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> ch[i][j];

	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (ch[i][j] == 'L' && !vis[i][j]) {
				dfs(i, j);
				ans++;
			}
		}
	}
	cout << ans;
	return 0;
}
